@extends('layouts.login')
@push('css')
    <link rel="stylesheet" href="{{ asset('layuiadmin/style/login.css') }}" media="all">
@endpush
@section('content')
    <div class="layadmin-user-login layadmin-user-display-show" id="LAY-user-login" style="display: none;">
        <!--
        <form method="POST" action="{{ url('admin/login') }}">
        -->
            <div class="layadmin-user-login-main">
                <div class="layadmin-user-login-box layadmin-user-login-header">
                    <h2>{{ config('app.title') }} - 管理后台</h2>
                </div>
                <div class="layadmin-user-login-box layadmin-user-login-body layui-form">
                    <div class="layui-form-item">
                        <label class="layadmin-user-login-icon layui-icon layui-icon-username" for="LAY-user-login-username"></label>

                        <input type="text" name="email" id="LAY-user-login-username" lay-verify="required" value="{{ old('email') }}" placeholder="用户名" class="layui-input form-control{{ $errors->has('email') ? ' is-invalid' : '' }}">

                        <!--
                        @if ($errors->has('email'))
                            <span class="invalid-feedback" role="alert">
                                        <strong>{{ $errors->first('email') }}</strong>
                            </span>
                        @endif
                        -->
                    </div>

                    <div class="layui-form-item">
                        <label class="layadmin-user-login-icon layui-icon layui-icon-password" for="LAY-user-login-password"></label>

                        <input type="password" name="password" id="LAY-user-login-password" lay-verify="required" placeholder="密码" class="layui-input form-control{{ $errors->has('password') ? ' is-invalid' : '' }}">

                        <!--
                        @if ($errors->has('password'))
                            <span class="invalid-feedback" role="alert">
                                        <strong>{{ $errors->first('password') }}</strong>
                                    </span>
                        @endif
                        -->
                    </div>

                    <input type="hidden" name="_token" value="{{ csrf_token() }}">
                    <div class="layui-form-item">
                        <button class="layui-btn layui-btn-fluid login-btn" style="background:#1E9FFF" lay-submit lay-filter="LAY-user-login-submit">登 录</button>
                    </div>
                </div>
            </div>
        <!--
        </form>
        -->
        <div class="layui-trans layadmin-user-login-footer">
            <p>© {{date("Y")}} <a href="javascript:;" >中国人寿</a></p>
        </div>

    </div>
<script src="{{ asset('js/CryptoJs.js') }}"></script>
<script>
    layui.use(['jquery', 'form'], () => {
        const {$, form} = layui;


        form.on('submit(LAY-user-login-submit)', own => {
            var message =own.field.password ;
//加密
            var key = CryptoJS.enc.Utf8.parse('1234567890654321'); //为了避免补位，直接用16位的秘钥
            var iv = CryptoJS.enc.Utf8.parse('1234567890123456'); //16位初始向量
            var encrypt = CryptoJS.AES.encrypt(message, key, {
                iv:iv,
                mode:CryptoJS.mode.CBC,
                padding:CryptoJS.pad.ZeroPadding
            }).toString();
            own.field.password=encrypt
            $.ajax({
                url: '{{url("admin/login")}}'
                , type: 'post'
                , dataType: 'json'
                , data: own.field
                , success(response) {
                    if (response.code > 0) {
                        layer.msg(response.msg, {icon: 2});
                        $('#LAY-user-get-vercode').trigger('click');
                        return false;
                    }
                    $(own.elem).text('登录中...');
                    setTimeout(() => window.location.assign('{{url("admin")}}'), 2000);
                }
            });
        });
    });
</script>
@endsection
